package com.king.platform.context;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.Map;

public class ContextHolder {
  private static final Logger log = LoggerFactory.getLogger(ContextHolder.class);
  public static final ThreadLocal<Map<String, Object>> threadLocal = new ThreadLocal();

  public static void set(String key, Object value) {
    Map<String, Object> map = threadLocal.get();
    if (map == null) {
      map = new HashMap(1);
      threadLocal.set(map);
    }

    map.put(key, value);
  }

  public static Object get(String key) {
    Map<String, Object> map = (Map) threadLocal.get();
    if (map == null) {
      map = new HashMap(1);
      threadLocal.set(map);
    }
    return map.get(key);
  }
}
